import Vuex, {Store} from "vuex"
import Vue from "vue";

// 求和相关配置
const countOption = {
    // 开启命名空间
    namespaced: true,
    actions: {
        /**
         *
         * @param context
         * @param value
         * 没有第三个参数了
         */
        jia(context, value) {
            console.log("actions - jia调用")
            context.commit("JIA", value)
        },
        jian(context, value) {
            console.log("actions - jian调用")
            context.commit("JIAN", value)
        },
        jiaOdd(context, value) {
            if (context.state.sum % 2 !== 0) {
                console.log("actions - jiaOdd调用")
                context.commit("JIAODD", value)
            }
        },
        jiaWait(context, value) {
            console.log("actions - jiaOdd调用")
            context.commit("JIAODD", value)
        }
    },
    mutations:{
        JIA(state, value) {
            console.log("mutations - JIA调用")
            state.sum += value
        },
        JIAN(state, value) {
            console.log("mutations - JIA调用")
            state.sum -= value
        },
        JIAODD(state, value) {
            console.log("mutations - JIA调用")
            state.sum += value
        }
    },
    state:{
        sum: 0,
        school: "冯镠霖学校",
        subject: "前端"
    },
    getters: {
        bigSum(state) {
            return state.sum * 10
        }
    }
}

// 人员管理相关的配置
const personOption = {
    actions: {},
    mutations:{
        ADD_PERSON(state, value) {

        }
    },
    state:{
        personList: [
            {id: "001", name: "张三"}
        ]
    },
    getters: {

    }
}

Vue.use(Vuex)

let store = new Store({
    modules: {
        // 开启的命名空间，key，就是
        a11223: countOption,
        b: personOption
    }
});

export default store